import _imports
from pathlib import Path
import pybi as pbi
from pybi.easyEcharts.base import BaseChart


class Template:
    """docstring for Template."""

    def __init__(self, chart_opts: BaseChart, main_title: str, sub_title: str):
        self.chart_opts = chart_opts
        self.main_title = main_title
        self.sub_title = sub_title

        self.mainBox, self._idx_box = self.__init()

        pbi.meta.add_style_tag(Path("template_charts.css").read_text())

    def __init(self):
        mainBox = pbi.box().set_classes("chart-box")
        idx_box = None

        with mainBox:
            with pbi.flowBox().set_classes("chart-header"):
                with pbi.box().set_classes("title-box"):
                    pbi.add_text(self.main_title).set_classes("title")
                    pbi.add_text(self.sub_title).set_classes("sub-title")

                pbi.space(auto_fill_row=True)
                idx_box = pbi.flowBox().set_classes("index-box")

            pbi.add_echart(
                self.chart_opts.set_prop_by_path("xAxis[0].axisLabel.color", "white")
                .set_prop_by_path("yAxis[0].axisLabel.color", "white")
                .set_prop_by_path("yAxis[0].splitLine.show", False)
                .set_prop_by_path("grid[0].top", 20)
                .set_prop_by_path("legend[0].show", False)
                .set_prop_by_path(
                    "series[0].backgroundStryle.color", "rgba(55, 245, 224,1)"
                )
            ).set_classes("my-charts")

        return mainBox, idx_box

    def add_index(self, title: str, content: str):
        with pbi.box().set_classes("index-div"):
            pbi.add_text(title).set_classes("main-title")
            pbi.add_text(content).set_classes("content")
        return self
